//_______________________________________________________________________________________________________________
/****************************************************************************************************************/
/*                                                                                                              */
/*                     F L A G S                                                                                */
/*                                                                                                              */
/****************************************************************************************************************/

//------------------------------------------------------------------------------
// Create flags and clear all bits

#define OS_CreateFlags(flags)               OS_CreateFlag(flags)
#define OS_CreateFlag(flags)                flags = 0


//------------------------------------------------------------------------------
// Set flags to given value

#define OS_InitFlags(flags, value)           OS_InitFlag(flags, value)
#define OS_InitFlag(flags, value)           flags = value

//------------------------------------------------------------------------------
// Set bits in flag by given mask

#define OS_SetFlags(flags, mask)            OS_SetFlag(flags, mask)
#define OS_SetFlag(flags, mask)             flags |= mask


//------------------------------------------------------------------------------
// Clear bits in flag by given mask

#define OS_ClearFlags(flags, mask)          OS_ClearFlag(flags, mask)
#define OS_ClearFlag(flags, mask)           flags &= ~(mask)


//------------------------------------------------------------------------------
// Check for all bits in flag are set by given mask

#define OS_CheckAllFlags(flags, mask)       OS_CheckAllFlag(flags, mask)
#define OS_CheckAllFlag(flags, mask)        (((flags) & (mask))==(mask))
    
//------------------------------------------------------------------------------
// Check for any bit in flag is set by given mask

#define OS_CheckAnyFlags(flags, mask)       OS_CheckAnyFlag(flags, mask)
#define OS_CheckAnyFlag(flags, mask)        ((flags) & (mask))
    
//------------------------------------------------------------------------------
// Check for bits in flag are cleared by given mask

#define OS_CheckAllFlagsClear(flags, mask)  OS_CheckAllFlagClear(flags, mask)
#define OS_CheckAllFlagClear(flags, mask)   (((flags) & (mask)) == 0)
    
//------------------------------------------------------------------------------
// Check for any bit in flag is cleared by given mask

#define OS_CheckAnyFlagsClear(flags, mask)  OS_CheckAnyFlagClear(flags, mask)
#define OS_CheckAnyFlagClear(flags, mask)   (((flags) & (mask)) != (mask))
    

//------------------------------------------------------------------------------
// Wait for all bits in flags are set by given mask

#define OS_WaitAllFlags(flags, mask)        OS_WaitAllFlag(flags, mask)
#define OS_WaitAllFlag(flags, mask)                                     \
    {                                                                   \
        _OS_WAIT_EVENT(OS_CheckAllFlag(flags, mask));                  \
    }

//------------------------------------------------------------------------------
// Wait for any bit in flags is set by given mask 

#define OS_WaitAnyFlags(flags, mask)        OS_WaitAnyFlag(flags, mask)
#define OS_WaitAnyFlag(flags, mask)                                     \
    {                                                                   \
        _OS_WAIT_EVENT(OS_CheckAnyFlag(flags, mask));                   \
    }


//-------------------------------------------------------------------------------
// Wait for all bits in flags are set by given mask. Exit if timeout expired.

#define OS_WaitAllFlagsTimeout(flags, mask, timeout)    OS_WaitAllFlagTimeout(flags, mask, timeout)
#define OS_WaitAllFlagTimeout(flags, mask, timeout)                     \
    {                                                                   \
        _OS_WAIT_EVENT_TIMEOUT(OS_CheckAllFlag(flags, mask), timeout);  \
    }

//-------------------------------------------------------------------------------
// Wait for any bit in flags is set by given mask. Exit if timeout expired.

#define OS_WaitAnyFlagsTimeout(flags, mask, timeout)    OS_WaitAnyFlagTimeout(flags, mask, timeout)
#define OS_WaitAnyFlagTimeout(flags, mask, timeout)                     \
    {                                                                   \
        _OS_WAIT_EVENT_TIMEOUT(OS_CheckAnyFlag(flags, mask), timeout);  \
    }



//------------------------------------------------------------------------------
// Wait for all bits in flag are cleared by given mask 

#define OS_WaitAllFlagsClear(flags, mask)       OS_WaitAllFlagClear(flags, mask)
#define OS_WaitAllFlagClear(flags, mask)                                \
    {                                                                   \
        _OS_WAIT_EVENT(OS_CheckAllFlagClear(flags, mask));              \
    }

//------------------------------------------------------------------------------
// Wait for any bit in flag is cleared by given mask 

#define OS_WaitAnyFlagsClear(flags, mask)       OS_WaitAnyFlagClear(flags, mask)
#define OS_WaitAnyFlagClear(flags, mask)                                \
    {                                                                   \
        _OS_WAIT_EVENT(OS_CheckAnyFlagClear(flags, mask));              \
    }


//-------------------------------------------------------------------------------
// Wait for all bits in flag are cleared by given mask. Exit if timeout expired.

#define OS_WaitAllFlagsClearTimeout(flags, mask, timeout)   OS_WaitAllFlagClearTimeout(flags, mask, timeout)
#define OS_WaitAllFlagClearTimeout(flags, mask, timeout)                        \
    {                                                                           \
        _OS_WAIT_EVENT_TIMEOUT(OS_CheckAllFlagClear(flags, mask), timeout);     \
    }

//-------------------------------------------------------------------------------
// Wait for any bit in flag is cleared by given mask. Exit if timeout expired.

#define OS_WaitAnyFlagsClearTimeout(flags, mask, timeout)   OS_WaitAnyFlagClearTimeout(flags, mask, timeout)
#define OS_WaitAnyFlagClearTimeout(flags, mask, timeout)                        \
    {                                                                           \
        _OS_WAIT_EVENT_TIMEOUT(OS_CheckAnyFlagClear(flags, mask), timeout);     \
    }





